package ws_handler

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"path/filepath"
	"time"
)

func LiveTest(c *gin.Context) {
	file, err := c.FormFile("video")
	if err != nil {
		c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
		return
	}

	// 生成唯一文件名
	filename := fmt.Sprintf("video-%d.webm", time.Now().UnixNano())
	filepath := filepath.Join("uploads", filename)

	// 保存文件
	if err := c.SaveUploadedFile(file, filepath); err != nil {
		c.String(http.StatusInternalServerError, fmt.Sprintf("upload file err: %s", err.Error()))
		return
	}

	c.String(http.StatusOK, fmt.Sprintf("File %s uploaded successfully.", file.Filename))
}
